package org.peoples.ui.containers {
	
	import flash.filters.BevelFilter;
	import flash.filters.BitmapFilterQuality;
	
	import mx.containers.Panel;
	
	[Style(name="bevelAlphas", type="Array", arrayType="Number", inherit="yes")]
	[Style(name="bevelColors", type="Array", arrayType="uint", format="Color", inherit="yes")]
	public class BeveledPanel extends Panel {
		
		private var filtersChanged:Boolean = true;
		
		public function BeveledPanel() {
			super();
		}
		
		protected function drawFilters():void {
			var allFilters:Array = new Array();
			
			var alphas:Array = getStyle("bevelAlphas");
			var colors:Array = getStyle("bevelColors");
			
			if (alphas != null && colors != null) {
				var bevel:BevelFilter = new BevelFilter();
				bevel.highlightAlpha = alphas[0];
				bevel.highlightColor = colors[0];
				bevel.shadowAlpha = alphas[1];
				bevel.shadowColor = colors[1];
				bevel.blurX = 80;
				bevel.blurY = bevel.blurX;
				bevel.strength = 3;
				bevel.distance = 2;
				bevel.quality = BitmapFilterQuality.HIGH;
				
				allFilters.push(bevel);
			}
			
			filters = null;
			filters = allFilters;
		}
		
		override public function styleChanged(styleProp:String):void {
			super.styleChanged(styleProp);
			
			if (styleProp == "bevelAlphas" || styleProp == "bevelColors") {
				filtersChanged = true;
				return;
			}
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			
			if (filtersChanged) {
				filtersChanged = false;
				drawFilters();
			}
		}
		
	}
	
}